package j2024.j202407;

import java.util.Arrays;
import java.util.Scanner;
import java.util.Stack;

public class j0724 {
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int count = 0;
        StringBuilder ret = new StringBuilder();
        while(a!=0){
            ret.append((char) (a%10+'0'));
            count++;
            if(count==3){
                ret.append(',');
                count = 0;
            }
            a/=10;
        }
        ret.reverse();
        if(ret.charAt(0)==','){
            ret.deleteCharAt(0);
        }
        System.out.println(ret.toString());
    }

    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        if(a<=3){
            System.out.println(a);
        }else {
            int[] ret = new int[a+1];
            ret[2] = 2;
            ret[3] = 3;
            for (int i = 4; i <= a; i++) {
                ret[i] = ret[i-1]+ret[i-2];
            }
            System.out.println(ret[a]);
        }
    }

    public static void main3(String[] args) {
        int[] n = {11,10,0,0,12};
        boolean a = IsContinuous(n);
    }
    public static boolean IsContinuous (int[] numbers) {
        // write code here
        Arrays.sort(numbers);
        int count = 0;
        for (int i = 0; i < numbers.length; i++) {
            if(numbers[i]==0){
                count++;
            }else if(i!=0 && numbers[i]==numbers[i-1]){
                return false;
            }
        }
        if(count==4){
            return true;
        }
        Stack<Integer> ret = new Stack<>();
        for (int i = count; i < numbers.length; ) {
            if(ret.isEmpty()){
                ret.add(numbers[i]);
                i++;
                continue;
            }
            int  tmp = ret.peek();
            if(numbers[i] == tmp+1){
                ret.add(numbers[i]);
                i++;
            }else {
                if(count!=0){
                    ret.add(tmp+1);
                    count--;
                }else {
                    if(numbers[i]!=ret.peek()+1){
                        break;
                    }
                }
            }
        }
        while(count>0){
            ret.add(0);
            count--;
        }
        if(ret.size()==5){
            return true;
        }else {
            return false;
        }
    }


    /**
     * 24. 两两交换链表中的节点
     * @param head
     * @return
     */
    public ListNode swapPairs(ListNode head) {
        if(head==null || head.next==null){
            return head;
        }
        ListNode tmp = swapPairs(head.next.next);
        ListNode headN = head.next;
        head.next = tmp;
        headN.next = head;
        return headN;
    }

    /**
     * 50. Pow(x, n)
     * @param x
     * @param n
     * @return
     */
    public double myPow(double x, int n) {
        return n<0?1.0/pow(x,-n):pow(x,n);
    }
    public double pow(double x,int n){
        if(n==0){
            return 1.0;
        }
        double tmp = pow(x,n/2);
        return n%2==0? tmp*tmp : tmp*tmp*x;
    }


    /**
     * 209. 长度最小的子数组
     * @param args
     */
    public static void main4(String[] args) {
        int[] nums = {2,3,1,2,4,3};
        int a = minSubArrayLen(7,nums);
    }
    public static int minSubArrayLen(int target, int[] nums) {
        int sum = 0;
        int len = Integer.MAX_VALUE;
        int left = 0;
        int right = 0;
        while(left<=right && right<nums.length){
            if(sum<target){
                sum+=nums[right];
            }
            while(left<=right &&sum>=target){
                len = Math.min(len,right-left+1);
                sum-=nums[left++];
            }
            right++;
        }
        if(len==Integer.MAX_VALUE){
            return 0;
        }
        return len;
    }
}
